import { CamelCaseNamingStrategy } from '@adonisjs/lucid/orm'
import { SimplePaginatorMetaKeys } from '@adonisjs/lucid/types/querybuilder'
import string from '@adonisjs/core/helpers/string'
import type { LucidModel } from '@adonisjs/lucid/types/model'
import type { ModelRelations } from '@adonisjs/lucid/types/relations'

export class CustomCamelCaseNamingStrategy extends CamelCaseNamingStrategy {
  // tableName(model: LucidModel): string {
  //   return string.pluralize(string.snakeCase(model.name.replace('Model', '')))
  // }

  // serializedName(_model: LucidModel, attributeName: string): string {
  //   return attributeName
  // }

  // columnName(_model: LucidModel, attributeName: string): string {
  //   return attributeName
  // }

  relationForeignKey(
    relation: ModelRelations<LucidModel, LucidModel>['__opaque_type'],
    model: LucidModel,
    relatedModel: LucidModel
  ): string {
    const table = relation === 'belongsTo' ? relatedModel.table : model.table

    return `fk${string.pascalCase(table).slice(0, -1)}Id`
  }

  paginationMetaKeys(): SimplePaginatorMetaKeys {
    return {
      total: 'total',
      perPage: 'pageSize',
      currentPage: 'page',
    } as SimplePaginatorMetaKeys
  }
}
